Since C doesn't have bools, what is the proper variable to put in place of true in an algorithm that uses
do
{
// ...
} while(true);
???
Should a proper C programmer do
do
{
// ...
} while(1);
or is there a specific variable reserved to mean "something that is not zero/NULL" ?
Usually nowadays I see
while(1) {
...
}
It used to be common to see
for(;;) {
...
}
It all gets the point across.
Your question isn't really about bool (which modern C does have if you #include <stdbool.h>), it's about the best way to write an infinite loop.
Common idioms are:
while (1) {
/* ... */
}
and
for (;;) {
/* ... */
}
The latter looks a little obscure, but it's well-defined. Any of the three expressions in a for loop header can be omitted; if the second expression, which controls when the loop continues to execute, is omitted, it defaults to true.
while (1) is probably the most straightforward method -- but some some compilers might warn about a condition that's always true. for (;;) likely avoids that, since there is no (explicit) expression to warn about.
I personally wouldn't use a do/while loop, because the condition is at the bottom.
There are trickier ways to write an infinite loop (while (1 + 1 == 2) et al, but none of them are really worth the effort.
Either while (1) or for (;;) will be perfectly clear to anyone with a good understanding of C.
If you're using c89:
Create a boolean definition:
typedef int bool;
#define true 1
#define false 0
Or constants:
/* Boolean constants. */
#define TRUE 1
#define FALSE 0
This gives the int a meaning for you.
Or (as mentioned elsewhere here) if using c99:
#include <stdbool.h>
My experience of universities lately, is they require you to use c89.